﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
using System.Windows.Media.Imaging;

namespace WpfFeeCalculator.Converters
{
     [ValueConversion(typeof(String), typeof(BitmapImage))]
    public class ImageConverter : IValueConverter
    {
         Dictionary<String, String> mapping;
         string path = @"pack://application:,,,/Resources/";
         string noMapping = "skullandcrossbones.jpg";

       public ImageConverter()
       {
           mapping = new Dictionary<string, string>{{"USD","flag_USA.jpg"}, 
                                                    {"EUR","Euro.jpg"}, 
                                                    {"GBP","Flag_Great-Britain.jpg"},
                                                    {"AUD","Australia.jpg"},
                                                     {"CHF","Flag_Switzerland.jpg"}, };
       }
       
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            try
            {
                string flag = (string)value;
                if (mapping.ContainsKey(flag))
                    return new BitmapImage(new Uri(string.Concat(path,mapping[flag])));
                return new BitmapImage(new Uri(string.Concat(path, noMapping)));
            }
            catch
            {
                return new BitmapImage(new Uri(string.Concat(path, noMapping)));
            }

        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
